<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
</head>
<body>
<div id="vuebox">
    <table class="table table-bordered container">
        <thead>
        <tr>
            <th>编号</th>
            <th>名称</th>
            <th>性别</th>
            <th>年龄</th>
            <th>住址</th>
            <th>邮箱</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in studentList">
            <td>{{item.sid}}</td>
            <td><a @click="updateStu(item.sid)">{{item.sname}}</a></td>
            <td>{{item.sgender}}</td>
            <td>{{item.sage}}</td>
            <td>{{item.saddress}}</td>
            <td>{{item.semail}}</td>
        </tr>
        </tbody>
    </table>

    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" @click="hideModal(),clearForm()" >&times;</button>
                    <div class="modal-title">
                    学员信息
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <input v-model="ne_student.sid" id="sid" readonly type="hidden" class="form-control">
                        <div class="form-group">
                            <label for="sname" class="col-sm-2 control-label">姓名:</label>
                            <div class="col-sm-10">
                                <input v-model="ne_student.sname" id="sname" readonly type="text" class="form-control" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sgender" class="col-sm-2 control-label">年龄:</label>
                            <div class="col-sm-10">
                                <input v-model="ne_student.sgender" id="sgender" readonly type="text" class="form-control" placeholder="请输入图书摘要"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sage" class="col-sm-2 control-label">性别:</label>
                            <div class="col-sm-10">
                                <input v-model="ne_student.sage" id="sage" readonly type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="saddress" class="col-sm-2 control-label">家庭住址:</label>
                            <div class="col-sm-10">
                                <input v-model="ne_student.saddress" id="saddress" readonly type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="semail" class="col-sm-2 control-label">邮箱:</label>
                            <div class="col-sm-10">
                                <input v-model="ne_student.semail" id="semail" readonly type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal(),clearForm()">关闭</button>
                    <button class="btn btn-primary" @click="saveModal()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            studentList:{},
            ne_student:{
                sid:'',sname:'',sgender:'',sage:'',saddress:'',semail:''
            },
            saveRest:{}
        },
        methods: {
            select:function () {
                axios.get("/selectAll").then(res=>{this.studentList=res.data})
            },
            updateStu:function (sid) {
                axios({
                    url:"/selectById",
                    method:"get",
                    params:{sid:sid}
                }).then(res=>{
                    this.ne_student=res.data
                    this.showModal();
                })
            },
            showModal:function () {
                $('#mymodal').modal('show');
            },
            hideModal:function () {
                $('#mymodal').modal('hide');
            },
            clearForm:function () {
                $('#sid').val('');
                $('#sname').val('');
                $('#sgender').val('');
                $('#sage').val('');
                $('#saddress').val('');
                $('#semail').val('');
            },
            saveModal:function () {
                if (this.ne_student.sid==null&&this.ne_student.sname==null&&this.ne_student.sgender==null&&this.ne_student.sage==null&&this.ne_student.saddress==null,this.ne_student.semail==null){
                    alert("请填写完整的信息")
                }else{
                    axios.post("/updateStu",this.ne_student).then(res=>{
                        this.saveRest=res.data
                        if (this.saveRest.result=="success"){
                            alert("修改成功");
                            this.select(1);
                            this.hideModal();
                        }else {
                            alert("失败请联系管理员")
                            this.hideModal();
                        }
                    })
                }
            }
            
        },
        mounted(){
           this.select(1);
        }
    })
</script>